*This file creates industry skill heterogeneity figures D.1-D.2

*Define controls
global linearcontrols c.lnlabor_all1943#year  c.power_labor_share1943#year c.ln_relative_wage1943#year c.ln_value_prod1943#year c.ln_establishments1943#year c.skilled1943#year c.ln_inputs_all1943#year c.ln_valueadded1943#year 

global highcontrols c.lnlabor_all1943#year  c.power_labor_share1943#year c.ln_relative_wage1943#year c.ln_establishments1943#year c.skilled1943#year c.ln_inputs_all1943#year 

*Input industry data.
use "$path/industry_data.dta", clear

*Import industry skill. See paper for details.
joinby digt2 using "$path/ind_edu.dta", unmatched(master)

preserve
keep if year==1943 
keep hay80 isic repa_sharel
xtile q_edu = hay80, nq(4)
egen q1_std=std(repa_sharel*(q_edu==1))
egen q2_std=std(repa_sharel*(q_edu==2))
egen q3_std=std(repa_sharel*(q_edu==3))
egen q4_std=std(repa_sharel*(q_edu==4))
keep isic q_edu q1_std q2_std q3_std q4_std
tempfile q_edu
save `q_edu'
restore 
joinby isic using   `q_edu'

gen ln_repa_tot_post_q1=ln_repa_tot*post*(q_edu==1)
gen ln_repa_tot_post_q2=ln_repa_tot*post*(q_edu==2)
gen ln_repa_tot_post_q3=ln_repa_tot*post*(q_edu==3)
gen ln_repa_tot_post_q4=ln_repa_tot*post*(q_edu==4)

gen  post_q_edu_1=(q_edu==1)*post
gen  post_q_edu_2=(q_edu==2)*post
gen  post_q_edu_3=(q_edu==3)*post
gen  post_q_edu_4=(q_edu==4)*post

**High Low

est clear 

gen d2_s_post_q1=d2_s*post*(q_edu==1)
gen d2_s_post_q2=d2_s*post*(q_edu==2)
gen d2_s_post_q3=d2_s*post*(q_edu==3)
gen d2_s_post_q4=d2_s*post*(q_edu==4)

gen d1_s_post_q1=d1_s*post*(q_edu==1)
gen d1_s_post_q2=d1_s*post*(q_edu==2)
gen d1_s_post_q3=d1_s*post*(q_edu==3)
gen d1_s_post_q4=d1_s*post*(q_edu==4)

global highs d2_s_post_q1 d2_s_post_q2 d2_s_post_q3 d2_s_post_q4
global lows d1_s_post_q1 d1_s_post_q2 d1_s_post_q3 d1_s_post_q4

foreach var in ln_value_prod lnlabor_all ln_valueadded {
reghdfe `var' d2_s_post_q1 d2_s_post_q2 d2_s_post_q3 d2_s_post_q4   , absorb(year isic $highcontrols) vce(cluster isic) 
estimates store m`var'3
}

foreach var in ln_value_prod lnlabor_all ln_valueadded {
reghdfe `var' d2_s_post_q1 d2_s_post_q2 d2_s_post_q3 d2_s_post_q4  $lows  , absorb(year isic $highcontrols) vce(cluster isic) 
estimates store m`var'0
}

foreach var in ln_value_prod lnlabor_all ln_valueadded {
reghdfe `var' d2_s_post_q1 d2_s_post_q2 d2_s_post_q3 d2_s_post_q4    $lows if timberpaper==0  , absorb(year isic $highcontrols) vce(cluster isic) 
estimates store m`var'1
}

foreach var in ln_value_prod lnlabor_all ln_valueadded {
reghdfe `var' d2_s_post_q1 d2_s_post_q2 d2_s_post_q3 d2_s_post_q4  $posts $lows  if timberpaper==0  , absorb(year isic $highcontrols) vce(cluster isic) 
estimates store m`var'2
}

label var d2_s_post_q1 "High x Post x SQ1"
label var d2_s_post_q2 "High x Post x SQ2"
label var d2_s_post_q3 "High x Post x SQ3"
label var d2_s_post_q4 "High x Post x SQ4"

coefplot (mln_value_prod3,) (mln_value_prod0,   label("Baseline")) (mln_value_prod1) (mln_value_prod2, mcolor(purple) ciopts(color(purple))), ylab(-.2(.4)1.2) keep($highs) vertical yline(0, lcolor(maroon)) legend(order(2 4 6 8) label(2 "Only High") label(4 "Baseline (+ Low Exposure)") label(6 "Baseline + No Established") label(8 "No Established + Skill Quartile") position(6)) plotregion(lcolor(white)) graphregion(lcolor(white) fcolor(white) color(white))  title (Impacts on ln Production Value) ytitle(Estimate)

graph export "$graphs/hetero_skill_prod.eps", font(Times)  replace
graph export "$graphs/hetero_skill_prod.pdf",  font(Times)  replace

coefplot (mlnlabor_all3) (mlnlabor_all0,   label("Baseline")) (mlnlabor_all1) (mlnlabor_all2, mcolor(purple) ciopts(color(purple))),  ylab(-.2(.4)1.2) keep($highs) vertical yline(0, lcolor(maroon)) legend(order(2 4 6 8) label(2 "Only High") label(4 "Baseline (+ Low Exposure)") label(6 "Baseline + No Established") label(8 "No Established + Skill Quartile") position(6)) plotregion(lcolor(white)) graphregion(lcolor(white) fcolor(white) color(white)) title (Impacts on ln Labor Force) ytitle(Estimate)

graph export "$graphs/hetero_skill_labor.eps", font(Times)  replace
graph export "$graphs/hetero_skill_labor.pdf",  font(Times)  replace

est clear 

global linear ln_repa_tot_post_q1  ln_repa_tot_post_q2 ln_repa_tot_post_q3 ln_repa_tot_post_q4

foreach var in ln_value_prod lnlabor_all ln_valueadded {
reghdfe `var' ln_repa_tot_post_q1  ln_repa_tot_post_q2 ln_repa_tot_post_q3 ln_repa_tot_post_q4  , absorb(year isic $linearcontrols) vce(cluster isic) 
estimates store m`var'0

reghdfe `var' ln_repa_tot_post_q1  ln_repa_tot_post_q2 ln_repa_tot_post_q3 ln_repa_tot_post_q4   if timberpaper==0 , absorb(year isic $linearcontrols) vce(cluster isic) 
estimates store m`var'1

reghdfe `var' ln_repa_tot_post_q1  ln_repa_tot_post_q2 ln_repa_tot_post_q3 ln_repa_tot_post_q4  $posts if timberpaper==0 , absorb(year isic $linearcontrols) vce(cluster isic) 
estimates store m`var'2
}

label var ln_repa_tot_post_q1 "ln(Repa) x Post x q1"
label var ln_repa_tot_post_q2 "ln(Repa) x Post x q2"
label var ln_repa_tot_post_q3 "ln(Repa) x Post x q3"
label var ln_repa_tot_post_q4 "ln(Repa) x Post x q4"

coefplot (mln_value_prod0,   label("Baseline")) (mln_value_prod1) (mln_value_prod2,), keep($linear) ylab(-.05(.05).075)  vertical yline(0, lcolor(maroon))  legend(order(2 4 6) label(2 "Baseline") label(4 "No Established") label(6 "No Established + Edu level controls") position(6)) plotregion(lcolor(white)) graphregion(lcolor(white) fcolor(white) color(white)) 

graph export "$graphs/hetero_skill_prod_ln.eps", font(Times) replace
graph export "$graphs/hetero_skill_prod_ln.pdf",  font(Times) replace

coefplot (mlnlabor_all0,   label("Baseline")) (mlnlabor_all1) (mlnlabor_all2,), keep($linear) ylab(-.05(.05).075)  vertical yline(0, lcolor(maroon))  legend(order(2 4 6) label(2 "Baseline") label(4 "No Established") label(6 "No Established + Edu level controls") position(6)) plotregion(lcolor(white)) graphregion(lcolor(white) fcolor(white) color(white)) 

graph export "$graphs/hetero_skill_labor_ln.eps", font(Times) replace
graph export "$graphs/hetero_skill_labor_ln.pdf",  font(Times) replace
